package com.tg.app.helper;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.tg.app.widget.BottomSheetListDialog;
import com.tg.app.widget.BottomSheetListDialog.BottomSheetClickListener;
import com.tg.appcommon.android.TGLog;
import com.tg.data.http.entity.DeviceBellBean;

import java.util.ArrayList;
import java.util.List;

public class CameraBottomSheetDialogHelper {
    public static void createResolutionSheetDialogHelper(@NonNull BottomSheetListDialog helper, List<String> list, int index, final BottomSheetClickListener listener) {
        if (list==null||list.size()==0){
            TGLog.i("CameraBottomSheetDialogHelper","createResolutionSheetDialogHelper size  null or empty");
            return;
        }
        List<BottomSheetListDialog.BottomSheetItem> bottomSheetItems = new ArrayList<>();
        int selectIndex = -1;
        int count = 0;
        for (int i = 1; i < list.size(); i++){
            BottomSheetListDialog.BottomSheetItem bottomSheetItem = new BottomSheetListDialog.BottomSheetItem(BottomSheetListDialog.ACTION_RESOLUTION, 0, list.get(i));
            bottomSheetItems.add(bottomSheetItem);
            if (TextUtils.equals(list.get(0),list.get(i))){
                selectIndex = i - 1;
                count++;
            }
        }

        if (count > 1 && index != -1){
            selectIndex = index;
        }

        show(helper, listener, bottomSheetItems, selectIndex);
    }

    private static void show(@NonNull BottomSheetListDialog helper, BottomSheetClickListener listener, List<BottomSheetListDialog.BottomSheetItem> bottomSheetItems, int selectIndex) {
        helper.setData(bottomSheetItems);
        helper.setClickListener(listener);
        if (selectIndex == -1) {
            helper.setNoneSelected();
        } else {
            helper.setSelectedIndex(selectIndex);
        }
        helper.show();
    }

    public static void createSpeedSheetDialogHelper(@NonNull BottomSheetListDialog helper, List<String> list, final BottomSheetClickListener listener) {
        List<BottomSheetListDialog.BottomSheetItem> bottomSheetItems = new ArrayList<>();

        BottomSheetListDialog.BottomSheetItem bottomSheetItem1 = new BottomSheetListDialog.BottomSheetItem(BottomSheetListDialog.ACTION_SPEED_X, 0, list.get(1));
        BottomSheetListDialog.BottomSheetItem bottomSheetItem2 = new BottomSheetListDialog.BottomSheetItem(BottomSheetListDialog.ACTION_SPEED_2X, 0, list.get(2));
        BottomSheetListDialog.BottomSheetItem bottomSheetItem3 = new BottomSheetListDialog.BottomSheetItem(BottomSheetListDialog.ACTION_SPEED_4X, 0, list.get(3));

        bottomSheetItems.add(bottomSheetItem1);
        bottomSheetItems.add(bottomSheetItem2);
        bottomSheetItems.add(bottomSheetItem3);
        int selectIndex = -1;
        for (int i = 0; i < bottomSheetItems.size(); i++){
            if (list.get(0).equals(bottomSheetItems.get(i).text)){
                selectIndex = i;
                break;
            }
        }

        show(helper, listener, bottomSheetItems, selectIndex);
    }

    public static void showSettingsBottomSheet(@NonNull BottomSheetListDialog helper, List<BottomSheetListDialog.BottomSheetItem> bottomSheetItems, final BottomSheetClickListener listener) {
        helper.setData(bottomSheetItems);
        helper.setClickListener(listener);
        helper.setNoneSelected();
        helper.show();
    }

    public static void showLampSettingsBottomSheet(@NonNull BottomSheetListDialog helper, List<DeviceBellBean> bottomSheetItems, final BottomSheetClickListener listener) {
        helper.setLampData(bottomSheetItems);
        helper.setClickListener(listener);
        helper.setNoneSelected();
        helper.show();
    }
}
